<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <?php echo $html->script(array("jquery.min.js", "jquery.form.js", "jquery.validate.js", "jquery.pagination.js", "jquery.tablesorter.min.js", "jquery.tablednd.js", "datepicker.js")); ?>
        <?php
        echo $this->Html->css('datepicker');
        ?>
        <script type="text/javascript">
            // <![CDATA[
            function pad(value, length) {
                length = length || 2;
                return "0000".substr(0,length - Math.min(String(value).length, length)) + value;
            };
            // ]]>
        </script>
    </head>
    <body>
        <div id="result">
            <div class="div_header1">Add New Q-Admin</div>
            <form method="post" id="add_admin" action="<?php echo Configure::read('base_url') . "users/add"; ?>">
                <table cellspacing="0" id="mytable"  style="float:left;">
                    <tbody>
                        <tr>
                            <td colspan="2">
                                <table width="100%" border="0" cellspacing="0" cellpadding="3"  style="float:left;">
                                    <tr><td colspan="4" style="color: red;">All the entries with * are mandatory for signup. Please fill in all information correctly.</td></tr>
                                    <tr>
                                        <td width="266" align="right">
                                            First Name*
                                        </td>
                                        <td width="247">
                                            <?php
                                            echo $this->Form->input('User.first_name', array('label' => false, 'div' => false, 'class' => 'required'));
                                            ?>
                                        </td>
                                        <td width="266" align="right">
                                            Last Name*
                                        </td>
                                        <td width="247">
                                            <?php
                                            echo $this->Form->input('User.last_name', array('label' => false, 'div' => false, 'class' => 'required', 'size' => '19'));
                                            ?>
                                        </td>
                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            Street Address*
                                        </td>
                                        <td width="247" colspan="3">
                                            <?php
                                            echo $this->Form->input('address', array('label' => false, 'div' => false, 'class' => 'required medium'));
                                            ?>
                                        </td>

                                    </tr>
                                    <tr >
                                        <td width="266">

                                        </td>
                                        <td width="247" colspan="3">
                                            <?php
                                            echo $this->Form->input('address1', array('label' => false, 'div' => false, 'class' => 'medium'));
                                            ?>
                                        </td>

                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            City*
                                        </td>
                                        <td width="247" colspan="3">
                                            <div id="userCityIdWrapper">
                                                <?php
                                                echo $this->Form->input('User.city_id', array('label' => false, 'div' => false, 'class' => 'required'));
                                                ?>
                                            </div>
                                        </td>

                                    </tr>
                                    <tr>
                                        <td width="266" align="right">
                                            State*
                                        </td>
                                        <td width="247"><div id="userStateIdWrapper">
                                                <?php
                                                echo $this->Form->input('User.state_id', array('label' => false, 'div' => false, 'class' => 'required', 'selected' => 3435));
                                                ?></div>
                                        </td>
                                        <td width="266" align="right">
                                            Zip*
                                        </td>
                                        <td width="247">
                                            <?php
                                            echo $this->Form->input('User.zip', array('label' => false, 'div' => false, 'class' => 'required', 'size' => '19'));
                                            ?>
                                        </td>
                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            Country*
                                        </td>
                                        <td width="247" colspan="3">
                                            <?php
                                            echo $this->Form->input('User.country_id', array('label' => false, 'div' => false, 'class' => 'required', 'selected' => 223));
                                            ?>
                                        </td>

                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            Primary Phone # *
                                        </td>
                                        <td width="247" colspan="3">
                                            <?php
                                            echo $this->Form->input('phone1', array('label' => false, 'div' => false, 'maxlength' => "3", 'size' => '4', 'style' => 'float:left;margin-right:10px;'));
                                            echo $this->Form->input('phone2', array('label' => false, 'div' => false, 'maxlength' => "4", 'size' => '5', 'style' => 'float:left;margin-right:10px;'));
                                            echo $this->Form->input('phone3', array('label' => false, 'div' => false, 'maxlength' => "3", 'size' => '4', 'class' => 'required'));
                                            ?>
                                        </td>

                                    </tr>
                                    <tr>
                                        <td width="266" align="right">
                                            Email*
                                        </td>
                                        <td width="247">
                                            <?php
                                            echo $this->Form->input('email', array('id' => 'email', 'name' => 'email', 'label' => false,
                                                'div' => false, 'class' => 'required email'));
                                            ?>
                                        </td>
                                        <td width="266" align="right">
                                            Confirm Email*
                                        </td>
                                        <td width="247">
                                            <?php
                                            echo $this->Form->input('cemail', array('label' => false, 'name' => 'cemail', 'div' => false, 'size' => '19'));
                                            ?>
                                        </td>
                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            User Id*
                                        </td>
                                        <td width="247" colspan="3">
                                            <?php
                                            echo $this->Form->input('User.username', array('label' => false, 'div' => false,
                                                'name' => 'username', 'id' => 'username'));
                                            ?>
                                        </td>

                                    </tr>
                                    <tr>
                                        <td width="266" align="right">
                                            Password*
                                        </td>
                                        <td width="247">
                                            <?php
                                            echo $this->Form->input('password', array('label' => false, 'div' => false,
                                                'class' => 'required', 'name' => 'password', 'id' => 'password', 'type' => 'password'));
                                            ?>
                                        </td>
                                        <td width="266" align="right">
                                            Confirm Password*
                                        </td>
                                        <td width="247">
                                            <?php
                                            echo $this->Form->input('cpassword', array('label' => false, 'div' => false,
                                                'class' => 'required', 'name' => 'cpassword', 'id' => 'cpassword', 'type' => 'password', 'size' => '19'));
                                            ?>
                                        </td>
                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            Secret Question*
                                        </td>
                                        <td width="247" colspan="3">
                                            <?php
                                            echo $this->Form->input('User.secretquestion_id', array('empty' => 'Select your Secret question', 'div' => false, 'label' => false, 'class' => 'required', 'style' => "width:195px"));
                                            ?>
                                        </td>

                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            Your Secret Answer*
                                        </td>
                                        <td width="247" colspan="3">
                                            <?php
                                            echo $this->Form->input('User.ques_ans', array('label' => false, 'div' => false, 'class' => 'required'));
                                            ?>
                                        </td>

                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            Date of Birth*
                                        </td>
                                        <td width="247" colspan="3"  align="left"  class="errorcls">
                                            <input type="text" readonly class="w16em required" id="selectDate" name="data[User][dateofbirth]" />
                                            <?php
                                            /* echo $this->Form->input('User.dateofbirth',array('label'=>false,'div'=>false,
                                              'class'=>'required','minYear'=>1900)); */
                                            ?>
                                            <script type="text/javascript">
                                                var today     = new Date(),
                                                // low range, 35 days before today's date
                                                //rangeLow  = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 35),
                                                // low range, form today's date
                                                rangeLow  = new Date(today.getFullYear()-150, today.getMonth(), today.getDate()),
                                                // high range, one year after today's date
                                                rangeHigh = new Date(today.getFullYear()-18, today.getMonth(), today.getDate())

                                                var opts = {
                                                    formElements:{"selectDate":"Y-ds-m-ds-d"},
                                                    showWeeks:true,
                                                    statusFormat:"l-cc-sp-d-sp-F-sp-Y",
                                                    // Set some dynamically calculated ranges
                                                    rangeLow:rangeLow.getFullYear() + "" + pad(rangeLow.getMonth()+1) + pad(rangeLow.getDate()),
                                                    rangeHigh:rangeHigh.getFullYear() + "" + pad(rangeHigh.getMonth()+1) + pad(rangeHigh.getDate())

                                                };
                                                if(jQuery("#fd-selectDate").html()!=null){
                                                    jQuery('#fd-selectDate').remove();
                                                }
                                                datePickerController.createDatePicker(opts);



                                                // <![CDATA[
                                                /* var opts = {
                                                            formElements:{"selectDate":"Y-ds-m-ds-d"},
                                                            showWeeks:true,
                                                            // Show a status bar and use the format "l-cc-sp-d-sp-F-sp-Y" (e.g. Friday, 25 September 2009)
                                                            statusFormat:"l-cc-sp-d-sp-F-sp-Y"
                                                    };
                                                    //alert(jQuery("#fd-selectDate").html());
                                                    if(jQuery("#fd-selectDate").html()!=null){
                                                       jQuery('#fd-selectDate').remove();
                                                    }
                                                    datePickerController.createDatePicker(opts);*/
                                                // ]]>
                                            </script>
                                        </td>

                                    </tr>
                                    <tr >
                                        <td width="266" align="right">
                                            Commission Rate*
                                        </td>
                                        <td width="247" colspan="3" class="errorcls">
                                            <input type="hidden" name="data[User][brandsid]" id="hdID" />
                                            <input type="hidden" name="data[User][styleid]" id="hdID2" />
                                            <input type="hidden" name="data[User][conditionsid]" id="hdID3" />
                                            <?php
                                            echo $this->Form->input('User.commission', array('label' => false, 'div' => false, 'class' => 'required number', 'size' => '8', 'style' => 'float:left;margin-right:10px;'));
                                            ?>%
                                        </td>

                                    </tr>
                                    <tr >
                                        <td width="266" colspan="4" >
                                            Permissions*
                                        </td>
                                    </tr>
                                    <tr >
                                        <td width="266" colspan="4">
                                            <div> <a href="#?w=500" rel="popup_name" class="poplight">Click here to select the brands for this Q-Admin</a>

                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td width="144">

                                        </td>
                                        <td width="347"><input type="submit" style="background:#73AE0B; color:#fff; font-size:14px;" name="button" id="button" value="Submit" /></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </tbody></table>
            </form>
        </div>
        <div id="popup_name" class="popup_block">
            <?php echo $html->script(array("jquery.min.js")); ?>
            <script type="text/javascript">

                jQuery(document).ready(function(){
                    //Populate City drop down on change State drop down
                    jQuery("#UserStateId").live('change',function () {
                        var stateId=jQuery(this).val();
                        var URL="<?php echo Configure::read('base_url'); ?>users/loadCity/"+stateId;          
                        jQuery("#UserCityId").html("<option value='0'>loading...</option>");
                        jQuery("#userCityIdWrapper").load(URL);
        
                    });
                    //Populate State drop down on change Country dropdown
                    jQuery("#UserCountryId").live('change',function () {
                        var countryId=jQuery(this).val();
                        var URL="<?php echo Configure::read('base_url'); ?>users/loadState/"+countryId;          
                        jQuery("#UserStateId").html("<option value='0'>loading...</option>");
                        jQuery("#userStateIdWrapper").load(URL);
        
                    });
                    //Check all
                    jQuery("#select_brand_all").click(function()
                    {
                        var checked_status = this.checked;
                                
                        jQuery("input[id=global_brand]").each(function()
                        {
                            this.checked = checked_status;
                            var brandid= jQuery(this).val();
                            if(jQuery(this).attr('id')=='global_brand')
                                var style='Global Brand';
                            if(jQuery(this).attr('id')=='global_style')
                                var style='Global Style';
                            if(jQuery(this).attr('id')=='global_condition')
                                var style='Global Condition';
                            if(checked_status==true){
                                         
                                        
                                        
                                jQuery.ajax({
                                    url : "<?php echo $html->url(array('controller' => 'users', 'action' => 'brandcheck')); ?>/"+brandid+'/'+style,
                                    success : function (html) {
                                        jQuery("#"+brandid).html(html);
                                    }
                                });
                                            
                            }else{ 
                                jQuery("#"+brandid).html("");
                            }

                                    
                        });
                    });
                    jQuery("#select_style_all").click(function()
                    {
                        /*var checked_status = this.checked;
                                    $("input[id=global_style]").each(function()
                                    {
                                            this.checked = checked_status;
                                    });*/
                        var checked_status = this.checked;
                                
                        jQuery("input[id=global_style]").each(function()
                        {
                            this.checked = checked_status;
                            var brandid= jQuery(this).val();
                            if(jQuery(this).attr('id')=='global_brand')
                                var style='Global Brand';
                            if(jQuery(this).attr('id')=='global_style')
                                var style='Global Style';
                            if(jQuery(this).attr('id')=='global_condition')
                                var style='Global Condition';
                            if(checked_status==true){
                                         
                                        
                                        
                                jQuery.ajax({
                                    url : "<?php echo $html->url(array('controller' => 'users', 'action' => 'brandcheck')); ?>/"+brandid+'/'+style,
                                    success : function (html) {
                                        jQuery("#"+brandid).html(html);
                                    }
                                });
                                            
                            }else{ 
                                jQuery("#"+brandid).html("");
                            }

                                    
                        });

                    });
                    $("#select_condition_all").click(function()
                    {
                        var checked_status = this.checked;

                        jQuery("input[id=global_condition]").each(function()
                        {
                            this.checked = checked_status;
                            var brandid= jQuery(this).val();
                            if(jQuery(this).attr('id')=='global_brand')
                                var style='Global Brand';
                            if(jQuery(this).attr('id')=='global_style')
                                var style='Global Style';
                            if(jQuery(this).attr('id')=='global_condition')
                                var style='Global Condition';
                            if(checked_status==true){



                                jQuery.ajax({
                                    url : "<?php echo $html->url(array('controller' => 'users', 'action' => 'brandcheck')); ?>/"+brandid+'/'+style,
                                    success : function (html) {
                                        jQuery("#"+brandid).html(html);
                                    }
                                });

                            }else{
                                jQuery("#"+brandid).html("");
                            }


                        });
                    });

            
                    jQuery(":button#canb").click(function () {
                        jQuery('#fade , .popup_block').fadeOut(function() {
                            jQuery('#fade, a.close').remove();  //fade them both out
                        });
                        return false;
                    });

                    jQuery(":button#addb").click(function () {
                    
                        //hdIDValue=jQuery("input[name=test]").val();
                        hdIDValue=jQuery("form#brand").serialize();
                        jQuery.ajax({
                            url : baseurl+"users/brandaccess/",
                            data:hdIDValue,
                            dataType: 'json',
                            type:'POST',
                            success : function (data) {
                                  
                                window.parent.document.getElementById('hdID').value=data.hdIDValue;
                                window.parent.document.getElementById('hdID2').value=data.hdIDValuest;
                                window.parent.document.getElementById('hdID3').value=data.hdIDValuecon;
                                jQuery('#fade , .popup_block').fadeOut(function() {
                                    jQuery('#fade, a.close').remove();  //fade them both out
                                });
                                return false;
                            }
                        });

                    });


                });
            </script>
            <script type="text/javascript">
                function branchk(param){
                    var brandid= jQuery(param).val();
                    if(jQuery(param).attr('id')=='global_brand')
                        var style='Global Brand';
                    if(jQuery(param).attr('id')=='global_style')
                        var style='Global Style';
                    if(jQuery(param).attr('id')=='global_condition')
                        var style='Global Condition';
                    if(param.checked==true){
                        jQuery.ajax({
                            url : "<?php echo $html->url(array('controller' => 'users', 'action' => 'brandcheck')); ?>/"+brandid+'/'+style,
                            success : function (html) {
                                jQuery("#"+brandid).html(html);
                            }
                        });
                    }else{
                        jQuery("#"+brandid).html("");
                    }
              
                }
            </script>

            <form method="post" id="brand" action="javascript:void(0);">
                <table width="100%" cellspacing="0"  id="suggest_global_content" style="display:block;">
                    <tr><td colspan="2"><b>Global Brands</b></td></tr>
                    <tr>
                        <td width="30"><input type="checkbox" id="select_brand_all"></td>
                        <td width="97%">Select all</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <?php
                                $i = 0;
                                foreach ($this->data['global_brand'] as $brand):
                                    $class = null;
                                    if ($i++ % 2 == 0)
                                        $class = ' class="alt"';
                                    ?>
                                    <tr>
                                        <td width="30" <?php echo $class; ?>><input type="checkbox" name="data[global_brand][]" onClick="return branchk(this);" id="global_brand" value="<?php echo $brand['Brand']['id']; ?>" /></td>
                                        <td <?php echo $class; ?>><?php echo $brand['Brand']['brand_description']; ?><span id="<?php echo $brand['Brand']['id']; ?>" style="color:red; margin-left:5px;"></span></td>
                                    </tr>
                                <?php endforeach; ?>
                            </table></td>
                    </tr>
                    <tr><td colspan="2"><b>Global Style</b></td></tr>
                    <tr>
                        <td width="30"><input type="checkbox" id="select_style_all"></td>
                        <td width="97%">Select all</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <?php
                                $i = 0;
                                foreach ($this->data['global_style'] as $brand):
                                    $class = null;
                                    if ($i++ % 2 == 0)
                                        $class = ' class="alt"';
                                    ?>
                                    <tr>
                                        <td width="30" <?php echo $class; ?>><input type="checkbox" name="data[global_style][]"  onClick="return branchk(this);" id="global_style" value="<?php echo $brand['Brand']['id']; ?>" /></td>
                                        <td <?php echo $class; ?>><?php echo $brand['Brand']['brand_description']; ?><span id="<?php echo $brand['Brand']['id']; ?>" style="color:red; margin-left:5px;"></span></td>
                                    </tr>
                                <?php endforeach; ?>
                            </table></td>
                    </tr>
                    <tr><td colspan="2"><b>Global Condition</b></td></tr>
                    <tr>
                        <td width="30"><input type="checkbox" id="select_condition_all"></td>
                        <td width="97%">Select all</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <?php
                                $i = 0;
                                foreach ($this->data['global_condition'] as $brand):
                                    $class = null;
                                    if ($i++ % 2 == 0)
                                        $class = ' class="alt"';
                                    ?>
                                    <tr>
                                        <td width="30" <?php echo $class; ?>><input type="checkbox" name="data[global_condition][]" onClick="return branchk(this);" id="global_condition" value="<?php echo $brand['Brand']['id']; ?>" /></td>
                                        <td <?php echo $class; ?>><?php echo $brand['Brand']['brand_description']; ?><span id="<?php echo $brand['Brand']['id']; ?>" style="color:red; margin-left:5px;"></span></td>
                                    </tr>
                                <?php endforeach; ?>
                            </table></td>
                    </tr>

                </table>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="30" align="right"><input type="button" name="Add" value="Proceed" id="addb"/></td>
                        <td width="30"> <input id="canb" type="button" name="cancel" value="Cancel" /></td>
                    </tr>

                </table>

            </form>
        </div>

        <script type="text/javascript">
            jQuery(document).ready(function(){

                jQuery.validator.addMethod("alphaNumeric", function (value, element) {
                    return this.optional(element) || /^[0-9a-zA-Z]+$/.test(value);
                }, "Username must contain only letters, numbers.");


                jQuery("#category_table").tablesorter({headers: { 2:{sorter: false},3:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}});

                var v = jQuery("#add_admin").validate({
                    rules: {
                        email:{
                            'required':true,
                            'email':true,
                            remote: {
                                url: baseurl+"users/emailcheck",
                                type: "post",
                                data: {
                                    email: function() {
                                        return jQuery("#email").val();
                                    }
                                }
                            }

                        } ,
                        cemail: {
                            required: true,
                            equalTo: '#email'
                        },
                        password: 'required',
                        cpassword: {
                            required: true,
                            equalTo: '#password'
                        },
                        username: {
                            required: true,
                            alphaNumeric: true,
                            minlength: 5,
                            remote: {
                                url: baseurl+"users/usercheck",
                                type: "post",
                                data: {
                                    username: function() {
                                        return jQuery("#username").val();
                                    }
                                }
                            }
                        }
                    },
                    submitHandler: function(form) {
                        jQuery(form).ajaxSubmit({
                            target: "#result"
                        });
                    }
                });


            });
      

        </script>
    </body>
</html>
<style type="text/css">

    #fade { /*--Transparent background layer--*/
        display: none; /*--hidden by default--*/

        position: fixed; left: 0; top: 0;
        width: 100%; height: 100%;

    }
    .popup_block{
        display: none; /*--hidden by default--*/
        background: #fff;
        padding: 20px;
        border: 0px solid #ddd;
        float: left;
        font-size: 1.2em;
        position: fixed;
        top: 50%; left: 50%;

        /*--CSS3 Box Shadows--*/
        -webkit-box-shadow: 0px 0px 20px #000;
        -moz-box-shadow: 0px 0px 20px #000;
        box-shadow: 0px 0px 20px #000;
        /*--CSS3 Rounded Corners--*/
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;
        max-height: 400px;
        overflow: auto;
    }
    img.btn_close {
        float: left;
        margin: -25px 0px 0 -25px;
        border: 0px;
    }
    /*--Making IE6 Understand Fixed Positioning--*/
    *html #fade {
        position: absolute;
    }
    *html .popup_block {
        position: absolute;
    }
    .errorcls input,.errorcls label{
        float: left;

    }
</style>
<script type="text/javascript">
    jQuery(document).ready(function() {
        //When you click on a link with class of poplight and the href starts with a #
        jQuery('a.poplight[href^=#]').click(function() {
            var popID = jQuery(this).attr('rel'); //Get Popup Name
            var popURL = jQuery(this).attr('href'); //Get Popup href to define size

            //Pull Query & Variables from href URL
            var query= popURL.split('?');
            var dim= query[1].split('&');
            var popWidth = dim[0].split('=')[1]; //Gets the first query string value

            //Fade in the Popup and add close button
            jQuery('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="../img/close-bg.png" class="btn_close" title="Close Window" alt="Close" /></a>');

            //Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
            var popMargTop = (jQuery('#' + popID).height() + 80) / 2;
            var popMargLeft = (jQuery('#' + popID).width() + 80) / 2;

            //Apply Margin to Popup
            jQuery('#' + popID).css({
                'margin-top' : -popMargTop,
                'margin-left' : -popMargLeft
            });

            //Fade in Background
            jQuery('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
            jQuery('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies

            return false;
        });

        //Close Popups and Fade Layer
        jQuery('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
            jQuery('#fade , .popup_block').fadeOut(function() {
                jQuery('#fade, a.close').remove();  //fade them both out
            });
            return false;
        });

    });
</script>